package com.nova.bluetooth.base;

import androidx.lifecycle.ViewModel;

import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;


/**
 * 备用
 */
public class BaseViewModel extends ViewModel {

    @Override
    protected void onCleared() {
        unSubscribe();
        super.onCleared();
    }

    private CompositeDisposable mCompositeDisposable;

    public void register(Disposable d) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeDisposable();
        }
        mCompositeDisposable.add(d);
    }


    public void unSubscribe() {
        if (mCompositeDisposable != null && !mCompositeDisposable.isDisposed()) {
            mCompositeDisposable.dispose();// 取消订阅
        }
    }
}
